import {
	TreeExpBarActionType,
	ICtrlEvent,
	ITreeExpBarAbility,
	ITreeExpBarControllerParams,
	ITreeExpBarModel,
	ITreeExpBarStore,
	IParam,
	ITreeExpBarController,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getCtrlClassNames,
	handleCtrlAction,
	handleCtrlDestroy,
	handleCtrlInit,
	handleQuickSearch,
	handleToolbarItemClick,
	useCtrlAction,
	useCtrlBasic,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';

/**
 * 树导航输入参数
 *
 * @export
 * @return {*}
 */
export function useTreeExpBarProps() {
	return {
		...useCtrlProps(),
		openView: Function,
		newView: Function,
	};
}

/**
 * 树导航基础参数
 *
 * @export
 * @param {ITreeExpBarModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useTreeExpBarBasic(model: ITreeExpBarModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		const classNames = getCtrlClassNames(model, props);
		Object.assign(classNames, {
			'app-control-expbar': true,
		});
		return classNames;
	};
	return {
		...useCtrlBasic(model, props),
		getClassNames,
		handleToolbarItemClick,
		handleQuickSearch,
		handleCtrlDestroy,
		handleCtrlInit,
		handleCtrlAction,
	};
}

/**
 * 树导航部件行为
 *
 * @export
 */
export function useTreeExpBarAction(
	controller: ITreeExpBarController<ITreeExpBarStore, ITreeExpBarAbility>
) {
	return {
		...useCtrlAction(controller),
	};
}

/**
 * 树导航部件控制器
 *
 * @export
 */
export function useTreeExpBarControllerParams<
	S extends ITreeExpBarStore,
	M extends ITreeExpBarModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<TreeExpBarActionType, ITreeExpBarAbility>>,
	otherParams: IParam = {}
): ITreeExpBarControllerParams<TreeExpBarActionType, ITreeExpBarAbility> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
		openView: props.openView,
		newView: props.newView,
	};
}
